package atm;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

/**
 * 菜单
 */
public class MenuPanel extends JPanel implements ActionListener{
    private AtmGUI atmGUI;
    private JButton searchBtn = new JButton(new ImageIcon("images\\buttonFind.jpg"));
    private JButton getBtn = new JButton(new ImageIcon("images\\buttonGet.jpg"));
    private JButton saveBtn = new JButton(new ImageIcon("images\\buttonSave.jpg"));

    private JButton changePwdBtn = new JButton(new ImageIcon("images\\buttonModify.jpg"));
    private JButton transferBtn = new JButton(new ImageIcon("images\\zzz.jpg"));
    private JButton offBtn = new JButton(new ImageIcon("images\\buttonOff.jpg"));
    private int index;
    public MenuPanel(AtmGUI atmGUI){
        this.atmGUI = atmGUI;
        this.setLayout(null);
        this.setOpaque(false);
        searchBtn.setBounds(0,100,140,50);
        searchBtn.addActionListener(this);
        this.add(searchBtn);
        getBtn.setBounds(0,200,140,50);
        getBtn.addActionListener(this);
        this.add(getBtn);
        saveBtn.setBounds(0,300,140,50);
        saveBtn.addActionListener(this);
        this.add(saveBtn);
        changePwdBtn.setBounds(870,100,140,50);
        changePwdBtn.addActionListener(this);
        this.add(changePwdBtn);
        transferBtn.setBounds(870,200,140,50);
        transferBtn.addActionListener(this);
        this.add(transferBtn);
        offBtn.setBounds(870,300,140,50);
        offBtn.addActionListener(this);
        this.add(offBtn);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        ArrayList<User> users = atmGUI.getUsers();
        if (e.getSource() == offBtn){
            atmGUI.showPanel("login");
        } else if (e.getSource() == searchBtn){
            atmGUI.showPanel("search");
        }else if (e.getSource() == getBtn){
            atmGUI.showPanel("get");
        }else if (e.getSource() == changePwdBtn){
            atmGUI.showPanel("changePwd");
        }else if (e.getSource() == saveBtn){
            atmGUI.showPanel("save");
        }else if (e.getSource() == transferBtn){
            atmGUI.showPanel("transfer");
        }
    }
}
